In [114]:
from sympy import *
from sympy import abc
from IPython.display import display, Math, Latex
from sympy.interactive import printing
printing.init_printing(use_latex=True)

Optimal Control Problem

Minimize $$\int_0^Tf(t,x,u)~dt$$ subject to $$ \begin{cases} x'(t) = b(t,x,u)\\ x(0) = x_0 \end{cases} $$


In [121]:
t, x, u= symbols('t x u')
Vt, Vx = symbols('V_t V_x')
f = x + 0.5 * u**2
b = x + u

Hamilton-Jacobi-Bellman Equation


In [122]:
hjbeq = r'\frac{\partial V}{\partial t} + \min_u \left[' + latex(f) + r'+\frac{\partial V}{\partial x}\left(' + latex(b)+ r'\right)\right] = 0'
display(Math(hjbeq))

hjbbd = r'V(T,x)=0'
display(Math(hjbbd))


$$\frac{\partial V}{\partial t} + \min_u \left[u^{2}+\frac{\partial V}{\partial x}\left(u\right)\right] = 0$$
$$V(T,x)=0$$

Successive Approximation


In [123]:
sahjbeq = r'\frac{\partial V_k}{\partial t} + ' + latex(f) + r'+\frac{\partial V_k}{\partial x} \left(' + latex(b) + r'\right)= 0'
display(Math(sahjbeq.replace('u', 'u_k')))

sahjbbd = r'V_k(T,x)=0'
display(Math(sahjbbd))


$$\frac{\partial V_k}{\partial t} + u_k^{2}+\frac{\partial V_k}{\partial x} \left(u_k\right)= 0$$
$$V_k(T,x)=0$$

In [124]:
update = r'u_{k+1} = \arg\min_{u_k}\left[' + latex(f) + r'+\frac{\partial V_k}{\partial x} \left(' + latex(b) + r'\right)\right]'
display(Math(update))


$$u_{k+1} = \arg\min_{u_k}\left[u^{2}+\frac{\partial V_k}{\partial x} \left(u\right)\right]$$

In [ ]: